@extends('admin.layouts.base')
@section('title','广告列表')
@section('pageHeader','广告列表')

@section('content')
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h5 class="box-title">用户提现列表</h5>
                </div>
                @if (session('info'))
                    <div id="jg" class="callout callout-info">
                        <p>{{ session('info') }}</p>
                    </div>
                @endif
                <div class="box-footer">
                    <table id="records-table" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>请选择</th>
                            <th>序号</th>
                            <th>流水号</th>
                            <th>手机号</th>
                            <th>充值金额</th>
                            <th>币数量</th>
                            <th>充值类型</th>
                            <th>客户地址</th>
                            <th>平台地址</th>
                            <th>号码</th>
                            <th>充值时间</th>
                            <th>处理结果</th>
                            <th>处理时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        <meta name="csrf-token" content="{{ csrf_token() }}">
{{--<!--                        --><?php //var_dump($data);die;?>--}}
                        @foreach($data as $key => $item)
                            {{--{{dd($item->getUser()->phone)}}--}}
                            <tr>
                                <td>
                                    <input name="" type="checkbox" value="{{ $item->id }}"/>
                                    <input name="" type="hidden" value="{{ $item->user_id }}"/>
                                </td>

                                <td>{{ $key + 1 }}</td>
                                <td style="word-wrap:break-word;word-break:break-all">
                                    ****{{ substr($item->order_id, -6) }}
                                </td>
                                <td>{{ $item->getUser()->phone }}</td>
                                <td style="color:#00a65a;">
                                    {{ $item->money }}
                                </td>
                                <td style="color:#00a65a;">
                                    {{ $item->number }}
                                </td>


                                <td>{{ \App\Models\Orm\CoinLog::$status_type[$item->type] }}</td>
                                <td>{{ $item->customer_wallet }}</td>
                                <td>{{ $item->wallet }}</td>
                                <td>{{ \App\Models\Orm\CoinLog::$status_pay[$item->pay_type] }}{{ $item->name }}</td>
                                <td>{{ $item->created_at }}</td>
                            @if($item->status ==2)
                                <td><font color="red">{{ \App\Models\Orm\CoinLog::$status_text[$item->status] }}</font></td>
                                @elseif($item->status ==3)
                                    <td><font color="green">{{ \App\Models\Orm\CoinLog::$status_text[$item->status] }}</font></td>
                                    @else
                                    <td><font color="blue">{{ \App\Models\Orm\CoinLog::$status_text[$item->status] }}</font></td>
                                @endif
                                    <td>{{ $item->updated_at }}</td>
                                <td>
                                @if(Gate::forUser(auth('admin')->user())->check('admin.order.show'))
                                    <a href="{{ url('/admin/order/create/' . $item->id) }}">
                                        加币
                                    </a>
                                    <a href="{{ url('/admin/order/edit/' . $item->id) }}">
                                            提币
                                    </a>
                                @endif</td>
                            </tr>
                        @endforeach

                        </tbody>

                    </table>
                    <div>
                        <button type="button" class="btn btn-warning" onclick="rejectRecords()">标记已驳回</button>
                        <button type="button" class="btn btn-success" onclick="lendRecords()">标记已通过</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
<script>
    window.onload = function () {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        setInterval(function () {
            $("#jg").fadeOut(1000);
        }, 3000);

        $("#records-table").DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "stateSave": true,
            "autoWidth": true,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
                "sInfoEmtpy": "找不到相关数据",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...", "sSearch": "搜索",
                "sUrl": "", //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt  
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext": " 下一页 ",
                    "sLast": " 最后一页 "
                }
            } //多语言配置  
        });

    }
        // 冻结用户
        function freezeUser() {
            /**
             * 先获取被选元素,得到集合
             * 判断集合长度,如果等于0返回错误
             * 循环遍历集合,获取每个元素的下一个元素的value,即为用户id,放进一个数组
             */
            var checked_list = $('input:checked');


            if (checked_list.length == 0) {
                alert('请选择数据');
                return false;
            }

            if (confirm("确认全部标记为冻结?")) {

                var user_id_list = [];
                for (var i = 0; i < checked_list.length; i++) {
                    var current_user_id = checked_list.eq(i).next().val();
                    // 如果用户id列表里没有这个id,则将其加入
                    if (user_id_list.indexOf(current_user_id) < 0) {
                        user_id_list.push(current_user_id);
                    }
                }

                $.ajax({
                    type: 'POST',
                    url: '/admin/order/freezeUsers',
                    data: {user_id_list: user_id_list},
                    success: function (data) {
                        if (data.code != 0) {
                            alert(data.msg);
                            return false;
                        }
                        location.reload();
                    }
                });
            }
        }

        // 标记已驳回
        function rejectRecords() {
            handler(0);
        }

        // 标记已放款
        function lendRecords() {
            handler(1);
        }

        // 公共处理方法
        function handler(o) {
            /**
             * 判断是什么动作
             * 先获取被选元素,得到集合
             * 判断集合长度,如果等于0返回错误
             * 循环遍历集合,获取每个元素的value,即为提现记录id,放进一个数组
             */
            if (o == 0) {
                confirm_msg = '确认全部标记为被驳回?';
                ajax_url = '/admin/order/rejectRecords';
            } else {
                confirm_msg = '确认全部标记为已放款?';
                ajax_url = '/admin/order/lendRecords';
            }

            var checked_list = $('input:checked');


            if (checked_list.length == 0) {
                alert('请选择数据');
                return false;
            }

            if (confirm(confirm_msg)) {
                var withdraw_id_list = [];
                for (var i = 0; i < checked_list.length; i++) {
                    var current_withdraw_id = checked_list.eq(i).val();
                    // 如果提现id列表里没有这个id,则将其加入
                    if (withdraw_id_list.indexOf(current_withdraw_id) < 0) {
                        withdraw_id_list.push(current_withdraw_id);
                    }
                }
                $.ajax({
                    type: 'POST',
                    url: ajax_url,
                    data: {withdraw_id_list: withdraw_id_list},
                    success: function (data) {
                        if (data.code != 0) {
                            alert(data.msg);
                            return false;
                        }
                        location.reload();
                    }
                });
            }
        }

</script>